#include "client-socket.h"
#include "commonfunc.h"

int ClientSocketProc::msgSend(uint32_t msgType, google::protobuf::Message& hbReq)
{
    uint32_t size;
    char *buf = getBaseProto().encode(msgType, hbReq, size);
    if(buf){
        uv_buf_t buffer = uv_buf_init(buf, size);

        uv_write_t*  write_req = reinterpret_cast<uv_write_t*>(malloc(sizeof(*write_req)));
        return uv_write(write_req, reinterpret_cast<uv_stream_t*>(&getSocket()), &buffer, 1, _on_write);
    }
    return -INT_MAX;
}


void ClientSocketProc::_on_write(uv_write_t* req, int status)
{
    free(req);
}
